package com.ruoyi.project.jiaqin.commentreply.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.commentreply.domain.NewsCommentReply;
import com.ruoyi.project.jiaqin.commentreply.service.INewsCommentReplyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 评论回复Controller
 *
 * @author admin
 * @date 2020-12-15
 */
@Controller
@RequestMapping("/jiaqin/commentreply")
public class NewsCommentReplyController extends BaseController {
    private String prefix = "jiaqin/commentreply";

    @Autowired
    private INewsCommentReplyService newsCommentReplyService;

    @RequiresPermissions("jiaqin:commentreply:view")
    @GetMapping()
    public String commentreply()
    {
        return prefix + "/commentreply";
    }

    /**
     * 查询评论回复列表
     */
    @RequiresPermissions("jiaqin:commentreply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewsCommentReply newsCommentReply)
    {
        startPage();
        List<NewsCommentReply> list = newsCommentReplyService.selectNewsCommentReplyList(newsCommentReply);
        return getDataTable(list);
    }

    /**
     * 导出评论回复列表
     */
    @RequiresPermissions("jiaqin:commentreply:export")
    @Log(title = "评论回复", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NewsCommentReply newsCommentReply)
    {
        List<NewsCommentReply> list = newsCommentReplyService.selectNewsCommentReplyList(newsCommentReply);
        ExcelUtil<NewsCommentReply> util = new ExcelUtil<NewsCommentReply>(NewsCommentReply.class);
        return util.exportExcel(list, "commentreply");
    }

    /**
     * 新增评论回复
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评论回复
     */
    @RequiresPermissions("jiaqin:commentreply:add")
    @Log(title = "评论回复", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NewsCommentReply newsCommentReply)
    {
        return toAjax(newsCommentReplyService.insertNewsCommentReply(newsCommentReply));
    }

    /**
     * 修改评论回复
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        NewsCommentReply newsCommentReply = newsCommentReplyService.selectNewsCommentReplyById(id);
        mmap.put("newsCommentReply", newsCommentReply);
        return prefix + "/edit";
    }

    /**
     * 修改保存评论回复
     */
    @RequiresPermissions("jiaqin:commentreply:edit")
    @Log(title = "评论回复", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewsCommentReply newsCommentReply)
    {
        return toAjax(newsCommentReplyService.updateNewsCommentReply(newsCommentReply));
    }

    /**
     * 删除评论回复
     */
    @RequiresPermissions("jiaqin:commentreply:remove")
    @Log(title = "评论回复", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(newsCommentReplyService.deleteNewsCommentReplyByIds(ids));
    }
}
